package pt.compflow.activity.task;

import pt.compflow.Context;
import pt.compflow.activity.ActivityControllerListener;
import pt.compflow.interfaces.task.TaskInterfaceListener;

/**
 * Handles all Tasks and Assignments
 *
 */
public interface TaskController extends TaskInterfaceListener {
	
	/**
	 * Invoked when an error occurs inside one of the TaskController commands
	 * These include errors inside TaskInterface methods invoked in commands
	 * This method cancels all pending assignments for the task
	 */
	public void onCommandError(String jobUri, String taskUri, String interfaceUri);
	
//	public void startPending(String jobUri, String taskUri);
	
	/**
	 * Shuts down the TaskController and all its Threads/Commands
	 * May wait for termination up to 60 seconds
	 * @throws InterruptedException
	 */
	public void stop();
	
	public void start();
	
	/**
	 * Starts/runs the supplied Task
	 * @param taskUri of the task to start
	 * @throws InstantiationException
	 * @throws IllegalAccessException
	 * @throws ClassNotFoundException
	 */
	public void startTask(String jobUri, String taskUri);
	
	/**
	 * Cancels the supplied Task and its Assignments
	 * @param jobUri
	 * @param taskUri
	 */
	public void cancelTask(String jobUri, String taskUri, boolean isTimeout);
	
		
	public boolean addListener(ActivityControllerListener l);

	public boolean removeListener(ActivityControllerListener l);
	
	public void removeAllListeners();

	public Context getContext();
	
}

